clear all;
clear plot;

delete(instrfind);

cont = ServoController(7);

alpha = .1;

plot(1);
title('Infrared Sensor Input');
ylabel('Input');
xlabel('Index');
%table = zeros(1, 1000);
%slope = zeros(1, 1000);
i = 1;
prevValue = 0;

while (true)
   value = cont.getAnalogInput(5);
   %unfilteredTable(i) = value;
   table(i) = (alpha)*value + (1-alpha)*prevValue;
   i = i + 1;
   
   %slope(i) = abs(value-prevValue);
   
   %if (slope(i) > 75)
   %    disp(['Reaction ' num2str(i)]);
   %end
   
   prevValue = value;
   
   plot(table, 'Color', 'red');
   %plot(unfilteredTable, 'Color', 'blue');
   %plot(slope, 'Color', 'green');
   axis([0 (i + 1) 0 500]);
   hold on;
end